from flask import Blueprint,current_app
from flask_caching import Cache
import configparser
import sys
 
bp_app = Blueprint('bp_app ', __name__)

"""
读取配置文件
"""
try:
    cf = configparser.ConfigParser()
    cf.read('./conf/config.ini')
    redishost = cf.get('redis','redishost')
    redisport = cf.get('redis','redisport')
    redisdb = cf.get('redis','redisdb')
    # redispassword = cf.get('redis','redispassword')
except Exception as e:
    current_app.logger.debug('请确保config.ini是否存在,或配置不正确！')
    current_app.logger.debug(e)
    sys.exit(0)

bp_cache = Cache(config={'CACHE_TYPE': 'redis',          # Use Redis
              'CACHE_REDIS_HOST': redishost,  # Host, default 'localhost'
              'CACHE_REDIS_PORT': redisport,       # Port, default 6379
            #   'CACHE_REDIS_PASSWORD': redispassword,  # Password
              'CACHE_REDIS_DB': redisdb})